{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\logs/appendices_results.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 4 Jun 2024, 13:47:01
{txt}
{com}. 
. *Appendix A materials
.         /* Run do file creating Figures A1 and A2 */
.         do "${c -(}dr_code{c )-}/appendices/figureA1andA2.do"
{txt}
{com}. /* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
> by Micah Cameron-Harp and Nathan Hendricks
> 
> Code written by Micah Cameron-Harp
> May 16th, 2024
> 
> This do file creates Figures A1 and A2 displaying the sizes of adoption cohorts.
> */
. 
. *Define directories and set working directory
. /* NOTE - To replicate our results, you need to change the root directory address in the next line */
. global dr_root = "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{txt}
{com}. global dr_code = "${c -(}dr_root{c )-}\code"
{txt}
{com}. global dr_data = "${c -(}dr_root{c )-}\data"
{txt}
{com}. global dr_output = "${c -(}dr_root{c )-}\outputs"
{txt}
{com}. global dr_output_main = "${c -(}dr_root{c )-}\outputs\main_text"
{txt}
{com}. global dr_output_app = "${c -(}dr_root{c )-}\outputs\appendices"
{txt}
{com}. global dr_output_log = "${c -(}dr_root{c )-}\outputs\logs"
{txt}
{com}. global dr_temp = "${c -(}dr_root{c )-}\data\intermediate"
{txt}
{com}. cd "${c -(}dr_root{c )-}"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials
{txt}
{com}. 
. ***************************** Figure A1 ****************************************
. *Load flood to cp or lepa dataset
. import delimited using "$dr_temp\flood_cporlepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(405 vars, 40,907 obs)

{com}. keep wr_group cohort_flood_cplepa
{txt}
{com}. drop if cohort_flood_cplepa==0
{txt}(0 observations deleted)

{com}. duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(39,279 observations deleted)

{com}. hist cohort_flood_cplepa, ///
>         name(hist_flood_cplepa, replace) ///
>         title("Flood to center pivot", size(small) position(11)) ///
>         xtitle("") ytitle("", size(small) angle(vertical)) legend(off) ///
>         xsize(2) ysize(2.8) freq  discrete ///
>         xlabel(1991(4)2019, labsize(small) angle(vertical)) xlabel(1991(4)2019, labsize(small) angle(vertical)) ///
>         ylabel(0(50)200, labsize(small))
{txt}(start={res}1992{txt}, width={res}1{txt})
{res}{txt}
{com}. 
. *Load cp to LEPA
. import delimited using "$dr_temp\cp_lepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(412 vars, 99,024 obs)

{com}. keep wr_group cohort_cp_lepa
{txt}
{com}. drop if cohort_cp_lepa==0
{txt}(2,981 observations deleted)

{com}. duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(92,327 observations deleted)

{com}. hist cohort_cp_lepa, ///
>         title("Traditional center pivot to LEPA", size(small) position(11)) ///
>         name(hist_cp_lepa, replace) ///
>         xtitle("") legend(off) xtitle("") ytitle("", size(small) angle(vertical)) xsize(2) ysize(2.8) ///
>         freq  discrete ///
>         xlabel(1991(4)2019, labsize(small) angle(vertical)) ///
>         ylabel(0(200)1000, labsize(small))
{txt}(start={res}1992{txt}, width={res}1{txt})
{res}{txt}
{com}. 
. *combine graphs
. graph combine hist_flood_cplepa hist_cp_lepa, ///
>         rows(1) name(comb_gr, replace) ///
>         title("Cohort size", size(medsmall)) ///
>         b2title("Year of technology change", size(small)) l2title("Number of water right groups", size(small))
{res}{txt}
{com}. graph export "${c -(}dr_output_app{c )-}/figureA1.tif", replace wid(6500) height(4500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/figureA1.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
. ***************************** Figure A2 ****************************************
. *Now do flood to only cp
. import delimited using "$dr_temp\flood_cporlepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(405 vars, 40,907 obs)

{com}. xtset wr_group wua_year
{res}
{col 1}{txt:Panel variable: }{res:wr_group}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2019}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}.         keep if num_switch_flood_cp==1
{txt}(22,591 observations deleted)

{com}.         keep wr_group cohort_flood_cplepa
{txt}
{com}.         drop if cohort_flood_cplepa==0
{txt}(0 observations deleted)

{com}.         duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(17,586 observations deleted)

{com}.         hist cohort_flood_cplepa, ///
>                 name(hist_flood_onlycp, replace) ///
>                 title("Flood to traditional center pivot", size(small) position(11)) ///
>                 xtitle("") ytitle("", size(small) angle(vertical)) legend(off) ///
>                 xsize(2) ysize(2.8) freq  discrete ///
>                 xlabel(1991(4)2019, labsize(small) angle(vertical)) xlabel(1991(4)2019, labsize(small) angle(vertical)) ///
>                 ylabel(0(50)150, labsize(small))
{txt}(start={res}1992{txt}, width={res}1{txt})
{res}{txt}
{com}. 
. *Now do flood to only lepa
. import delimited using "$dr_temp\flood_cporlepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(405 vars, 40,907 obs)

{com}. xtset wr_group wua_year
{res}
{col 1}{txt:Panel variable: }{res:wr_group}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2019}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}.         keep if num_switch_flood_lepa==1
{txt}(18,316 observations deleted)

{com}.         keep wr_group cohort_flood_cplepa
{txt}
{com}.         drop if cohort_flood_cplepa==0
{txt}(0 observations deleted)

{com}.         duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(21,693 observations deleted)

{com}.         hist cohort_flood_cplepa, ///
>                 name(hist_flood_onlylepa, replace) ///
>                 title("Flood to LEPA", size(small) position(11)) ///
>                 xtitle("") ytitle("", size(small) angle(vertical)) legend(off) ///
>                 xsize(2) ysize(2.8) freq  discrete ///
>                 xlabel(1991(4)2019, labsize(small) angle(vertical)) xlabel(1991(4)2019, labsize(small) angle(vertical)) ///
>                 ylabel(0(50)150, labsize(small))
{txt}(start={res}1992{txt}, width={res}1{txt})
{res}{txt}
{com}. 
.                 *combine graphs
. graph combine hist_flood_onlycp hist_flood_onlylepa, ///
>         rows(1) name(comb_gr, replace) ///
>         title("Cohort size", size(medsmall)) ///
>         b2title("Year of technology change", size(small)) l2title("Number of water right groups", size(small))
{res}{txt}
{com}. graph export "${c -(}dr_output_app{c )-}/figureA2.tif", replace wid(6500) height(4500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/figureA2.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
{txt}end of do-file

{com}. 
.         /* Run do file creating Figure A3 */
.         do "${c -(}dr_code{c )-}/appendices/figureA3.do"
{txt}
{com}. /* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
> by Micah Cameron-Harp and Nathan Hendricks
> 
> Code written by Micah Cameron-Harp
> May 16th, 2024
> 
> This do file creates Figures A1 and A2 displaying the sizes of adoption cohorts.
> */
. 
. *Define directories and set working directory
. /* NOTE - To replicate our results, you need to change the root directory address in the next line */
. global dr_root = "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{txt}
{com}. global dr_code = "${c -(}dr_root{c )-}\code"
{txt}
{com}. global dr_data = "${c -(}dr_root{c )-}\data"
{txt}
{com}. global dr_output = "${c -(}dr_root{c )-}\outputs"
{txt}
{com}. global dr_output_main = "${c -(}dr_root{c )-}\outputs\main_text"
{txt}
{com}. global dr_output_app = "${c -(}dr_root{c )-}\outputs\appendices"
{txt}
{com}. global dr_output_log = "${c -(}dr_root{c )-}\outputs\logs"
{txt}
{com}. global dr_temp = "${c -(}dr_root{c )-}\data\intermediate"
{txt}
{com}. cd "${c -(}dr_root{c )-}"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials
{txt}
{com}. 
. *********************** Flood to CP or LEPA ************************************
. *Load in the data for the transition from flood to cp/lepa
. import delimited using "$dr_temp\flood_cporlepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(405 vars, 40,907 obs)

{com}. keep if num_switch_flood_cplepa==1
{txt}(0 observations deleted)

{com}. keep if wua_year <= 2015
{txt}(5,591 observations deleted)

{com}. 
. *Create three indicators for never-treated and not-yet-treated
. *'treat_status' indicates if a unit is currently treated
. gen nyt = cohort_flood_cplepa > 0 & wua_year < cohort_flood_cplepa
{txt}
{com}. gen nev_treat = cohort_flood_cplepa==0
{txt}
{com}. 
. *Process data
. collapse (sum) treat_status nyt nev_treat, by(wua_year)
{res}{txt}
{com}. 
. foreach var of varlist treat_status nyt nev_treat {c -(}
{txt}  2{com}.         gen share_`var' = 100*`var'/(treat_status+nyt+nev_treat)
{txt}  3{com}. {c )-}
{txt}
{com}. rename (treat_status nyt nev_treat share_treat_status share_nyt share_nev_treat) ///
>         (treatcat1 treatcat2 treatcat3 share_treatcat1 share_treatcat2 share_treatcat3)
{res}{txt}
{com}.         
. reshape long treatcat share_treatcat, i(wua_year) j(treat_cat)
{txt}(j = 1 2 3)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}          25   {txt}->   {res}75          
{txt}Number of variables        {res}           7   {txt}->   {res}4           
{txt}j variable (3 values)                     ->   {res}treat_cat
{txt}xij variables:
          {res}treatcat1 treatcat2 treatcat3   {txt}->   {res}treatcat
share_treatcat1 share_treatcat2 share_treatcat3{txt}->{res}share_treatcat
{txt}{hline 77}

{com}. rename treatcat num_wrgs
{res}{txt}
{com}. 
. gen treat_name = "Treated"
{txt}
{com}. replace treat_name = "Not-yet-treated" if treat_cat==2
{txt}variable {bf}{res}treat_name{sf}{txt} was {bf}{res}str7{sf}{txt} now {bf}{res}str15{sf}
{txt}(25 real changes made)

{com}. replace treat_name = "Never-treated" if treat_cat==3
{txt}(25 real changes made)

{com}. 
. label define treat_codes 1 "Treated" 2 "Not-yet-treated" 3 "Never-treated"
{txt}
{com}. label values treat_cat treat_codes
{txt}
{com}. 
. *Xtset and graph
. xtset treat_cat wua_year
{res}
{col 1}{txt:Panel variable: }{res:treat_cat}{txt: (strongly balanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2015}}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}.         xtline num_wrgs, overlay
{res}{txt}
{com}.                 
. *Stack the data 
. gen stack_wrgs  = .   // generate empty variables
{txt}(75 missing values generated)

{com}. gen stack_share_wrgs = .
{txt}(75 missing values generated)

{com}. sort wua_year treat_cat  // it is import to sort the data here.
{txt}
{com}. levelsof wua_year, local(years) 
{res}{txt}1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015

{com}.         foreach y of local years {c -(}
{txt}  2{com}.         summ treat_cat
{txt}  3{com}.         // take the first tech as it is
.         replace stack_wrgs = num_wrgs if wua_year==`y' & treat_cat==`r(min)'
{txt}  4{com}.         // iteratively add up the 
.         replace stack_wrgs = num_wrgs + stack_wrgs[_n-1]  if  wua_year==`y' & treat_cat!=`r(min)'  
{txt}  5{com}.           
.         * stack shares  
.         replace stack_share_wrgs = share_treatcat if  wua_year==`y' & treat_cat==`r(min)' 
{txt}  6{com}.         replace stack_share_wrgs = share_treatcat + stack_share_wrgs[_n-1] if  wua_year==`y' & treat_cat!=`r(min)'
{txt}  7{com}. {c )-}

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

{com}. 
. *Graph stacked share of acres
. xtline stack_share_wrgs, overlay 
{res}{txt}
{com}. 
. *Now fill in the regions and fancy graph 
. **** get the labels in order
. summ wua_year 

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         75        2003    7.259663       1991       2015
{txt}
{com}. gen tag = 1 if wua_year==`r(max)'
{txt}(72 missing values generated)

{com}. sort wua_year treat_cat
{txt}
{com}. *Generate rank variable 
. 
. *Reverse ordering 
. sort wua_year treat_cat
{txt}
{com}. summ treat_cat  

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         75           2    .8219949          1          3
{txt}
{com}. gen treat_cat2 = `r(max)' + 1 - treat_cat  // reverse the ordering
{txt}
{com}. sort wua_year treat_cat
{txt}
{com}. gen labely = .
{txt}(75 missing values generated)

{com}.  replace labely =  stack_share_wrgs / 2           if treat_cat==1 & tag==1
{txt}(1 real change made)

{com}.  replace labely = (stack_share_wrgs + stack_share_wrgs[_n-1]) / 2  if treat_cat!=1 & tag==1
{txt}(2 real changes made)

{com}. egen rank = rank(share_treatcat)   if tag==1 & share_treatcat > 0 & share_treatcat!=., f 
{txt}(73 missing values generated)

{com}.  
. format share_treatcat %9.1f
{txt}
{com}. gen labelval = treat_name + " (" + string(share_treatcat, "%9.1fc") + "%)"   if rank <= 10
{txt}(73 missing values generated)

{com}. levelsof treat_cat2, local(levels)
{res}{txt}1 2 3

{com}. local items = `r(r)'
{txt}
{com}.  
. foreach x of local levels {c -(}
{txt}  2{com}. display "`x'"
{txt}  3{com}. local x2 = `x' + 2
{txt}  4{com}. colorpalette mrc, n(7) nograph
{txt}  5{com}.  local stacklines2 `stacklines2' area stack_share_wrgs wua_year if treat_cat2 == `x', fcolor("`r(p`x2')'") lcolor(black) lwidth(*0.2) ||
{txt}  6{com}.  {c )-}
1
{res}2
3
{txt}
{com}. summ wua_year 

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         75        2003    7.259663       1991       2015
{txt}
{com}. local x1 = `r(min)'
{txt}
{com}. local x2 = `r(max)'
{txt}
{com}. summ wua_year

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         75        2003    7.259663       1991       2015
{txt}
{com}. summ treat_cat if wua_year==`r(max)'

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}          3           2           1          1          3
{txt}
{com}.   local ctot = `r(sum)'
{txt}
{com}.   local ctot : di %7.0fc `ctot'
{res}{txt}
{com}.   
. graph twoway `stacklines2' ///
>  (scatter labely wua_year if tag==1, ms(smcircle) msize(0.2) mcolor(black%0) mlabel(labelval) mlabsize(vsmall) mlabcolor(black) ) ///
>  , ///
>   legend(off) ///
>   ytitle("", size(vsmall) angle(vertical)) ///
>   ylabel(, labsize(vsmall) nogrid) ///
>   xtitle("") ///
>   xlabel(`x1'(2)`x2', labsize(vsmall) angle(vertical) nogrid) ///
>   xscale(range(1991 2021)) ///
>   title("Flood to center pivot", size(small) position(11)) ///
>   graphregion(margin(1 1 1 1)) xsize(4.5)
{res}{txt}
{com}.   
. *Save
. cd "${c -(}dr_output_app{c )-}"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices
{txt}
{com}. graph save treat_comp_over_time_floodtocplepa, replace
{res}{txt}file {bf:treat_comp_over_time_floodtocplepa.gph} saved

{com}. 
. *********************** CP to LEPA *********************************************
. *Load in the data for the transition cp to lepa
. import delimited using "$dr_temp\cp_lepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(412 vars, 99,024 obs)

{com}. 
. *Create three indicators for never-treated and not-yet-treated
. *'treat_status' indicates if a unit is currently treated
. gen nyt = cohort_cp_lepa > 0 & wua_year < cohort_cp_lepa
{txt}
{com}. gen nev_treat = cohort_cp_lepa==0
{txt}
{com}. 
. *Process data
. collapse (sum) treat_status nyt nev_treat, by(wua_year)
{res}{txt}
{com}. 
. foreach var of varlist treat_status nyt nev_treat {c -(}
{txt}  2{com}.         gen share_`var' = 100*`var'/(treat_status+nyt+nev_treat)
{txt}  3{com}. {c )-}
{txt}
{com}. rename (treat_status nyt nev_treat share_treat_status share_nyt share_nev_treat) ///
>         (treatcat1 treatcat2 treatcat3 share_treatcat1 share_treatcat2 share_treatcat3)
{res}{txt}
{com}.         
. reshape long treatcat share_treatcat, i(wua_year) j(treat_cat)
{txt}(j = 1 2 3)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}          29   {txt}->   {res}87          
{txt}Number of variables        {res}           7   {txt}->   {res}4           
{txt}j variable (3 values)                     ->   {res}treat_cat
{txt}xij variables:
          {res}treatcat1 treatcat2 treatcat3   {txt}->   {res}treatcat
share_treatcat1 share_treatcat2 share_treatcat3{txt}->{res}share_treatcat
{txt}{hline 77}

{com}. rename treatcat num_wrgs
{res}{txt}
{com}. 
. gen treat_name = "Treated"
{txt}
{com}. replace treat_name = "Not-yet-treated" if treat_cat==2
{txt}variable {bf}{res}treat_name{sf}{txt} was {bf}{res}str7{sf}{txt} now {bf}{res}str15{sf}
{txt}(29 real changes made)

{com}. replace treat_name = "Never-treated" if treat_cat==3
{txt}(29 real changes made)

{com}. 
. label define treat_codes 1 "Treated" 2 "Not-yet-treated" 3 "Never-treated"
{txt}
{com}. label values treat_cat treat_codes
{txt}
{com}. 
. *Xtset and graph
. xtset treat_cat wua_year
{res}
{col 1}{txt:Panel variable: }{res:treat_cat}{txt: (strongly balanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2019}}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}.         xtline num_wrgs, overlay
{res}{txt}
{com}.                 
. *Stack the data 
. gen stack_wrgs  = .   // generate empty variables
{txt}(87 missing values generated)

{com}. gen stack_share_wrgs = .
{txt}(87 missing values generated)

{com}. sort wua_year treat_cat  // it is import to sort the data here.
{txt}
{com}. levelsof wua_year, local(years) 
{res}{txt}1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019

{com}.         foreach y of local years {c -(}
{txt}  2{com}.         summ treat_cat
{txt}  3{com}.         // take the first tech as it is
.         replace stack_wrgs = num_wrgs if wua_year==`y' & treat_cat==`r(min)'
{txt}  4{com}.         // iteratively add up the 
.         replace stack_wrgs = num_wrgs + stack_wrgs[_n-1]  if  wua_year==`y' & treat_cat!=`r(min)'  
{txt}  5{com}.           
.         * stack shares  
.         replace stack_share_wrgs = share_treatcat if  wua_year==`y' & treat_cat==`r(min)' 
{txt}  6{com}.         replace stack_share_wrgs = share_treatcat + stack_share_wrgs[_n-1] if  wua_year==`y' & treat_cat!=`r(min)'
{txt}  7{com}. {c )-}

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)

{com}. 
. *Graph stacked share of acres
. xtline stack_share_wrgs, overlay 
{res}{txt}
{com}. 
. *Now fill in the regions and fancy graph 
. **** get the labels in order
. summ wua_year 

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         87        2005    8.415103       1991       2019
{txt}
{com}. gen tag = 1 if wua_year==`r(max)'
{txt}(84 missing values generated)

{com}. sort wua_year treat_cat
{txt}
{com}. *Generate rank variable 
. 
.         *Reverse ordering 
.         sort wua_year treat_cat
{txt}
{com}.         summ treat_cat  

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}         87           2    .8212299          1          3
{txt}
{com}.         gen treat_cat2 = `r(max)' + 1 - treat_cat  // reverse the ordering
{txt}
{com}. sort wua_year treat_cat
{txt}
{com}. gen labely = .
{txt}(87 missing values generated)

{com}.  replace labely =  stack_share_wrgs / 2           if treat_cat==1 & tag==1
{txt}(1 real change made)

{com}.  replace labely = (stack_share_wrgs + stack_share_wrgs[_n-1]) / 2  if treat_cat!=1 & tag==1
{txt}(2 real changes made)

{com}. egen rank = rank(share_treatcat)   if tag==1 & share_treatcat > 0 & share_treatcat!=., f 
{txt}(85 missing values generated)

{com}. replace rank = 2 if tag==1 & treat_cat2==2
{txt}(1 real change made)

{com}. replace rank = 3 if tag==1 & treat_cat2==1
{txt}(1 real change made)

{com}. *Make space for each label
. replace labely = 94.5 if rank==2
{txt}(1 real change made)

{com}. replace labely = 99 if rank==3
{txt}(1 real change made)

{com}. 
. 
.  
. format share_treatcat %9.1f
{txt}
{com}. gen labelval = treat_name + " (" + string(share_treatcat, "%9.1fc") + "%)"   if rank <= 10
{txt}(84 missing values generated)

{com}. levelsof treat_cat2, local(levels)
{res}{txt}1 2 3

{com}. local items = `r(r)'
{txt}
{com}.  
. foreach x of local levels {c -(}
{txt}  2{com}. display "`x'"
{txt}  3{com}. local x2 = `x' + 2
{txt}  4{com}. colorpalette mrc, n(7) nograph
{txt}  5{com}.  local stacklines2 `stacklines2' area stack_share_wrgs wua_year if treat_cat2 == `x', fcolor("`r(p`x2')'") lcolor(black) lwidth(*0.2) ||
{txt}  6{com}.  {c )-}
1
{res}2
3
{txt}
{com}. summ wua_year 

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         87        2005    8.415103       1991       2019
{txt}
{com}. local x1 = `r(min)'
{txt}
{com}. local x2 = `r(max)'
{txt}
{com}. summ wua_year

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 4}wua_year {c |}{res}         87        2005    8.415103       1991       2019
{txt}
{com}. summ treat_cat if wua_year==`r(max)'

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 3}treat_cat {c |}{res}          3           2           1          1          3
{txt}
{com}.   local ctot = `r(sum)'
{txt}
{com}.   local ctot : di %7.0fc `ctot'
{res}{txt}
{com}.   
. graph twoway `stacklines2' ///
>  (scatter labely wua_year if tag==1, ms(smcircle) msize(0.2) mcolor(black%0) mlabel(labelval) mlabsize(vsmall) mlabcolor(black) ) ///
>  , ///
>   legend(off) ///
>   ytitle("", size(vsmall) angle(vertical)) ///
>   ylabel(, labsize(vsmall) nogrid) ///
>   xtitle("") ///
>   xlabel(`x1'(2)`x2', labsize(vsmall) angle(vertical) nogrid) ///
>   xscale(range(1991 2025)) ///
>   title("Traditional center pivot to LEPA", size(small) position(11)) ///
>   graphregion(margin(1 1 1 1)) xsize(4.5)
{res}{txt}
{com}.  
. *Save
. cd "${c -(}dr_output_app{c )-}"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices
{txt}
{com}. graph save treat_comp_over_time_cptolepa, replace
{res}{txt}file {bf:treat_comp_over_time_cptolepa.gph} saved

{com}. 
. **************** Combine graphs into Figure A3 *********************************
. *Bring in the treatment composition graphs 
. graph use "${c -(}dr_output_app{c )-}\treat_comp_over_time_floodtocplepa.gph", name(flood_treat_comp, replace)
{res}{txt}
{com}. graph use "${c -(}dr_output_app{c )-}\treat_comp_over_time_cptolepa.gph", name(cplepa_treat_comp, replace)
{res}{txt}
{com}. 
. *Combine them
. graph combine flood_treat_comp cplepa_treat_comp,  ///
>         cols(1) name(comb_gr, replace) ///
>         title("", size(medsmall)) ///
>         b2title("Year", size(vsmall)) l2title("Percent of sample", size(vsmall)) ///
>         xsize(4.5) ysize(4.5)
{res}{txt}
{com}.         
. graph export "${c -(}dr_output_app{c )-}\figureA3.tif", replace wid(6500) height(6500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureA3.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
{txt}end of do-file

{com}. 
.         /* Run do file creating figures A4 and A5 */
.         do "${c -(}dr_code{c )-}/appendices/figureA4andA5.do"
{txt}
{com}. /* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
> by Micah Cameron-Harp and Nathan Hendricks
> 
> Code written by Micah Cameron-Harp
> May 16th, 2024
> 
> This do file creates Figures A4 and A5 displaying the pre-treatment irrigation
>         behavior by cohort.
> */
. 
. *Define directories and set working directory
. /* NOTE - To replicate our results, you need to change the root directory address in the next line */
. global dr_root = "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{txt}
{com}. global dr_code = "${c -(}dr_root{c )-}\code"
{txt}
{com}. global dr_data = "${c -(}dr_root{c )-}\data"
{txt}
{com}. global dr_output = "${c -(}dr_root{c )-}\outputs"
{txt}
{com}. global dr_output_main = "${c -(}dr_root{c )-}\outputs\main_text"
{txt}
{com}. global dr_output_app = "${c -(}dr_root{c )-}\outputs\appendices"
{txt}
{com}. global dr_output_log = "${c -(}dr_root{c )-}\outputs\logs"
{txt}
{com}. global dr_temp = "${c -(}dr_root{c )-}\data\intermediate"
{txt}
{com}. cd "${c -(}dr_root{c )-}"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials
{txt}
{com}. 
. *********************** Figure A.4 *********************************************
. *Load in the water right group collapsed data for the flood to cp/lepa transition
. import delimited using "$dr_temp\flood_cporlepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(405 vars, 40,907 obs)

{com}. *Limit to period of analysis
. keep if inrange(wua_year, 1991, 2015) 
{txt}(5,591 observations deleted)

{com}. *Make mean of each variables
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}. egen mean_`var' = mean(`var')
{txt}  3{com}. {c )-}
{txt}
{com}. *Drop not-yet-treated during the times when they are treated
. drop if wua_year >= cohort_flood_cplepa & cohort_flood_cplepa!=0
{txt}(23,248 observations deleted)

{com}. 
. *Create long difference variables
. xtset wr_group wua_year
{res}
{col 1}{txt:Panel variable: }{res:wr_group}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2015}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. 
. *Keep minimum year in dataset and last year before treatment
. keep if wua_year==min_year | wua_year==cohort_flood_cplepa - 1
{txt}(9,001 observations deleted)

{com}. drop if min_year==cohort_flood_cplepa - 1
{txt}(169 observations deleted)

{com}. gen ind_min_year = 0
{txt}
{com}. replace ind_min_year = 1 if min_year==wua_year
{txt}(1,459 real changes made)

{com}. 
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}.         gen min_year_`var' = `var'*ind_min_year
{txt}  3{com}.         bysort wr_group: egen min_`var' = max(min_year_`var')
{txt}  4{com}.         drop min_year_`var'
{txt}  5{com}. {c )-}
{txt}
{com}. keep if wua_year==cohort_flood_cplepa - 1
{txt}(1,459 observations deleted)

{com}. 
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}.         gen diff_`var' = `var' - min_`var'
{txt}  3{com}.         replace diff_`var' = 100*diff_`var'/mean_`var'
{txt}  4{com}. {c )-}
{txt}(1,434 real changes made)
(1,038 real changes made)
(1,436 real changes made)

{com}. 
. foreach var of varlist diff_af_used diff_acres_irr diff_depth_applied {c -(}
{txt}  2{com}. * Use egen to generate the median, quartiles, interquartile range (IQR), and mean. 
. bysort cohort_flood_cplepa: egen med_`var' = median(`var')
{txt}  3{com}. by cohort_flood_cplepa: egen lqt_`var' = pctile(`var'), p(25)
{txt}  4{com}. by cohort_flood_cplepa: egen uqt_`var' = pctile(`var'), p(75)
{txt}  5{com}. by cohort_flood_cplepa: egen iqr_`var' = iqr(`var')
{txt}  6{com}. by cohort_flood_cplepa: egen mean_`var' = mean(`var')
{txt}  7{com}. 
. * Find the lowest value that is more than lqt - 1.5 iqr 
. * this is used to form the lower "whisker" of the boxplot.
. gen l_`var' = `var' if(`var' >= lqt_`var'-1.5*iqr_`var')
{txt}  8{com}. by cohort_flood_cplepa: egen ls_`var' = min(l_`var')
{txt}  9{com}. 
. * Find the highest value that is less than uqt + 1.5 iqr 
. * this is used to form the upper "whisker" of the boxplot.
. gen u_`var' = `var' if(`var' <= uqt_`var'+1.5*iqr_`var')
{txt} 10{com}. by cohort_flood_cplepa: egen us_`var' = max(u_`var')
{txt} 11{com}. 
. * Find any outliers (i.e. values more than 1.5 IQRs from the upper and lower quartiles). 
. gen outliers_`var' = `var' if(`var'<=lqt_`var'-1.5*iqr_`var' | `var'>=uqt_`var'+1.5*iqr_`var')
{txt} 12{com}. {c )-}
{txt}(63 missing values generated)
(23 missing values generated)
(1,353 missing values generated)
(190 missing values generated)
(131 missing values generated)
(1,114 missing values generated)
(9 missing values generated)
(10 missing values generated)
(1,420 missing values generated)

{com}. 
. 
. *Plot for af_used
. twoway rbar lqt_diff_af_used med_diff_af_used cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_af_used uqt_diff_af_used cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_af_used ls_diff_af_used cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_af_used us_diff_af_used cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_af_used ls_diff_af_used cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_af_used us_diff_af_used cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Acre-feet withdrawn", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period", size(small)) graphregion(color(white) margin(zero)) ///
>            ylabel(-300 -150 0 150) ///
>            yscale(extend) ///
>            xtitle("Cohort", size(small)) ///
>            xscale(extend) /// 
>            name(flood_to_cplepa_afused, replace)
{res}{txt}
{com}.            
. *Plot for acres_irr
. twoway rbar lqt_diff_acres_irr med_diff_acres_irr cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_acres_irr uqt_diff_acres_irr cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_acres_irr ls_diff_acres_irr cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_acres_irr us_diff_acres_irr cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_acres_irr ls_diff_acres_irr cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_acres_irr us_diff_acres_irr cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Acres irrigated", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period") graphregion(color(white) margin(zero)) ///
>            xtitle("Cohort") ///
>            xscale(extend) /// 
>            ylabel(-200 -150 -100 -50 0 50) ///
>            yscale(extend) ///
>            name(flood_to_cplepa_acresirr, replace)
{res}{txt}
{com}.            
. *Plot for depth_applied
. twoway rbar lqt_diff_depth_applied med_diff_depth_applied cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_depth_applied uqt_diff_depth_applied cohort_flood_cplepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_depth_applied ls_diff_depth_applied cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_depth_applied us_diff_depth_applied cohort_flood_cplepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_depth_applied ls_diff_depth_applied cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_depth_applied us_diff_depth_applied cohort_flood_cplepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Depth-applied", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period") graphregion(color(white) margin(zero)) ///
>            xtitle("Cohort") ///
>            xscale(extend) /// 
>            name(flood_to_cplepa_depthapplied, replace)
{res}{txt}
{com}. 
. /* Combine the graphs */
. grc1leg2 flood_to_cplepa_afused flood_to_cplepa_acresirr flood_to_cplepa_depthapplied, ///
>         rows(3) cols(1) loff ///
>         xtob1title xtitlefrom(flood_to_cplepa_afused) ///
>         ytol1title ytitlefrom(flood_to_cplepa_afused) ///
>         labsize(vsmall) graphregion(color(white)) xsize(6.5) ysize(7.5) iscale(.8) ring(1) noautosize
{txt}-grc1leg2- working...
{res}{txt}
{com}. graph export "${c -(}dr_output_app{c )-}\figureA4.tif", width(6500) height(7700) replace
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureA4.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
. *********************** Figure A.5 *********************************************
. **Center pivot to LEPA
. import delimited using "$dr_temp\cp_lepa_prepped.csv", clear
{res}{txt}(encoding automatically selected: ISO-8859-1)
{text}(412 vars, 99,024 obs)

{com}. *Drop not-yet-treated during the times when they are treated
. drop if wua_year >= cohort_cp_lepa & cohort_cp_lepa!=0
{txt}(67,427 observations deleted)

{com}. tab treat_status

{txt}treat_statu {c |}
          s {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}     31,597      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}     31,597      100.00
{txt}
{com}. tab cohort_cp_lepa

{txt}cohort_cp_l {c |}
        epa {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}      2,981        9.43        9.43
{txt}       1992 {c |}{res}         83        0.26        9.70
{txt}       1993 {c |}{res}         70        0.22        9.92
{txt}       1994 {c |}{res}        128        0.41       10.32
{txt}       1995 {c |}{res}        214        0.68       11.00
{txt}       1996 {c |}{res}        281        0.89       11.89
{txt}       1997 {c |}{res}      4,712       14.91       26.80
{txt}       1998 {c |}{res}      3,108        9.84       36.64
{txt}       1999 {c |}{res}      1,813        5.74       42.38
{txt}       2000 {c |}{res}      3,325       10.52       52.90
{txt}       2001 {c |}{res}      1,449        4.59       57.49
{txt}       2002 {c |}{res}      1,521        4.81       62.30
{txt}       2003 {c |}{res}      1,438        4.55       66.85
{txt}       2004 {c |}{res}      1,090        3.45       70.30
{txt}       2005 {c |}{res}      1,141        3.61       73.91
{txt}       2006 {c |}{res}        798        2.53       76.44
{txt}       2007 {c |}{res}        860        2.72       79.16
{txt}       2008 {c |}{res}        503        1.59       80.75
{txt}       2009 {c |}{res}        681        2.16       82.91
{txt}       2010 {c |}{res}        547        1.73       84.64
{txt}       2011 {c |}{res}        472        1.49       86.13
{txt}       2012 {c |}{res}        373        1.18       87.31
{txt}       2013 {c |}{res}        783        2.48       89.79
{txt}       2014 {c |}{res}        392        1.24       91.03
{txt}       2015 {c |}{res}        515        1.63       92.66
{txt}       2016 {c |}{res}        323        1.02       93.68
{txt}       2017 {c |}{res}        348        1.10       94.78
{txt}       2018 {c |}{res}      1,290        4.08       98.87
{txt}       2019 {c |}{res}        358        1.13      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}     31,597      100.00
{txt}
{com}. 
. *Make mean of each variables
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}. egen mean_`var' = mean(`var')
{txt}  3{com}. {c )-}
{txt}
{com}. 
. *Create long difference variables
. xtset wr_group wua_year
{res}
{col 1}{txt:Panel variable: }{res:wr_group}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:wua_year}{txt:, }{res:{bind:1991}}{txt: to }{res:{bind:2019}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. 
. *Create max_year variable for the never-treated
. bysort wr_group: egen max_year = max(wua_year)
{txt}
{com}. gen max_nt_year = . 
{txt}(31,597 missing values generated)

{com}. replace max_nt_year = max_year if cohort_cp_lepa==0
{txt}(2,981 real changes made)

{com}. 
. *Keep minimum year in dataset and last year before treatment for adopters
.         *Keep minimum year and max year for never-treated
. keep if wua_year==min_year | wua_year==cohort_cp_lepa - 1 | wua_year == max_nt_year
{txt}(24,019 observations deleted)

{com}. drop if min_year==cohort_cp_lepa - 1
{txt}(330 observations deleted)

{com}. gen ind_min_year = 0
{txt}
{com}. replace ind_min_year = 1 if min_year==wua_year
{txt}(3,659 real changes made)

{com}. 
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}.         gen min_year_`var' = `var'*ind_min_year
{txt}  3{com}.         bysort wr_group: egen min_`var' = max(min_year_`var')
{txt}  4{com}.         drop min_year_`var'
{txt}  5{com}. {c )-}
{txt}
{com}. 
. *Keeper years
. gen keeper_year = 0
{txt}
{com}. replace keeper_year = 1 if wua_year==cohort_cp_lepa - 1 & cohort_cp_lepa!=0
{txt}(3,386 real changes made)

{com}. replace keeper_year = 1 if wua_year == max_nt_year
{txt}(273 real changes made)

{com}. keep if keeper_year==1
{txt}(3,589 observations deleted)

{com}. 
. foreach var of varlist af_used acres_irr depth_applied {c -(}
{txt}  2{com}.         gen diff_`var' = `var' - min_`var'
{txt}  3{com}.         replace diff_`var' = 100*diff_`var'/mean_`var'
{txt}  4{com}. {c )-}
{txt}(3,585 real changes made)
(1,710 real changes made)
(3,588 real changes made)

{com}. 
. // graph box diff_af_used, over(cohort_flood_cplepa)
. // graph box diff_acres_irr, over(cohort_flood_cplepa)
. // graph box diff_depth_applied, over(cohort_flood_cplepa)
. 
. foreach var of varlist diff_af_used diff_acres_irr diff_depth_applied {c -(}
{txt}  2{com}. * Use egen to generate the median, quartiles, interquartile range (IQR), and mean. 
. bysort cohort_cp_lepa: egen med_`var' = median(`var')
{txt}  3{com}. by cohort_cp_lepa: egen lqt_`var' = pctile(`var'), p(25)
{txt}  4{com}. by cohort_cp_lepa: egen uqt_`var' = pctile(`var'), p(75)
{txt}  5{com}. by cohort_cp_lepa: egen iqr_`var' = iqr(`var')
{txt}  6{com}. by cohort_cp_lepa: egen mean_`var' = mean(`var')
{txt}  7{com}. 
. * Find the lowest value that is more than lqt - 1.5 iqr 
. * this is used to form the lower "whisker" of the boxplot.
. gen l_`var' = `var' if(`var' >= lqt_`var'-1.5*iqr_`var')
{txt}  8{com}. by cohort_cp_lepa: egen ls_`var' = min(l_`var')
{txt}  9{com}. 
. * Find the highest value that is less than uqt + 1.5 iqr 
. * this is used to form the upper "whisker" of the boxplot.
. gen u_`var' = `var' if(`var' <= uqt_`var'+1.5*iqr_`var')
{txt} 10{com}. by cohort_cp_lepa: egen us_`var' = max(u_`var')
{txt} 11{com}. 
. * Find any outliers (i.e. values more than 1.5 IQRs from the upper and lower quartiles). 
. gen outliers_`var' = `var' if(`var'<=lqt_`var'-1.5*iqr_`var' | `var'>=uqt_`var'+1.5*iqr_`var')
{txt} 12{com}. {c )-}
{txt}(149 missing values generated)
(117 missing values generated)
(3,393 missing values generated)
(708 missing values generated)
(655 missing values generated)
(1,043 missing values generated)
(51 missing values generated)
(69 missing values generated)
(3,539 missing values generated)

{com}. 
. replace cohort_cp_lepa = 1990 if cohort_cp_lepa==0
{txt}(273 real changes made)

{com}. 
. 
. *Plot for af_used
. twoway rbar lqt_diff_af_used med_diff_af_used cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_af_used uqt_diff_af_used cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_af_used ls_diff_af_used cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_af_used us_diff_af_used cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_af_used ls_diff_af_used cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_af_used us_diff_af_used cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Acre-feet withdrawn", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period (% change)", size(small)) graphregion(color(white) margin(zero)) ///
>            xtitle("Cohort", size(small)) ///
>            xlabel(1990 "Never adopters" 1995 "1995" 2000 "2000" 2005 "2005" 2010 "2010" 2015 "2015") ///
>            xscale(extend) ///
>            name(cp_to_lepa_afused, replace)
{res}{txt}
{com}.            
. *Plot for acres_irr
. twoway rbar lqt_diff_acres_irr med_diff_acres_irr cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_acres_irr uqt_diff_acres_irr cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_acres_irr ls_diff_acres_irr cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_acres_irr us_diff_acres_irr cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_acres_irr ls_diff_acres_irr cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_acres_irr us_diff_acres_irr cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Acres irrigated", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period") graphregion(color(white) margin(zero)) ///
>            xtitle("Cohort") ///
>            xlabel(1990 "Never adopters" 1995 "1995" 2000 "2000" 2005 "2005" 2010 "2010" 2015 "2015") ///
>            xscale(extend) ///
>            name(cp_to_lepa_acresirr, replace)
{res}{txt}
{com}.            
. *Plot for depth_applied
. twoway rbar lqt_diff_depth_applied med_diff_depth_applied cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rbar med_diff_depth_applied uqt_diff_depth_applied cohort_cp_lepa, fcolor(gs12) lcolor(black) barw(.5) || ///
>        rspike lqt_diff_depth_applied ls_diff_depth_applied cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rspike uqt_diff_depth_applied us_diff_depth_applied cohort_cp_lepa, lwidth(.1) lcolor(black) || ///
>        rcap ls_diff_depth_applied ls_diff_depth_applied cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) || ///
>        rcap us_diff_depth_applied us_diff_depth_applied cohort_cp_lepa, msize(.5) lwidth(.1) lcolor(black) ///
>        legend(off) ///
>            title("Depth-applied", size(medsmall)) ///
>        ytitle("Difference over pre-treatment period") graphregion(color(white) margin(zero)) ///
>            xtitle("Cohort") ///
>            xlabel(1990 "Never adopters" 1995 "1995" 2000 "2000" 2005 "2005" 2010 "2010" 2015 "2015") ///
>            xscale(extend) ///
>            name(cp_to_lepa_depthapplied, replace)
{res}{txt}
{com}. 
. /* Combine the graphs */
. grc1leg2 cp_to_lepa_afused cp_to_lepa_acresirr cp_to_lepa_depthapplied, ///
>         rows(3) cols(1) loff ///
>         xtob1title xtitlefrom(cp_to_lepa_afused) ///
>         ytol1title ytitlefrom(cp_to_lepa_afused) ///
>         labsize(vsmall) graphregion(color(white)) xsize(6.5) ysize(7.5) iscale(.8) ring(1) noautosize
{txt}-grc1leg2- working...
{res}{txt}
{com}. graph export "${c -(}dr_output_app{c )-}\figureA5.tif", width(6500) height(7700) replace
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureA5.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
{txt}end of do-file

{com}. 
. *Appendix B materials
.         /* Run do file creating figures B1 and B2 */
.         do "${c -(}dr_code{c )-}/appendices/figureB1andB2.do"
{txt}
{com}. /* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
> by Micah Cameron-Harp and Nathan Hendricks
> 
> Code written by Micah Cameron-Harp
> May 16th, 2024
> 
> This do file runs the Monte Carlo simulation depicted in Figure B1 and then
>         creates Figure B3 displaying the resulting biased TWFE estimate.
> */
. 
. *Define directories and set working directory
.         /* NOTE - To replicate our results, you need to change the directory address in the next line */
. global dr_root = "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{txt}
{com}. global dr_data = "$dr_root\data"
{txt}
{com}. global dr_output = "$dr_root\outputs"
{txt}
{com}. global dr_output_main = "$dr_root\outputs\main_text"
{txt}
{com}. global dr_output_app = "$dr_root\outputs\appendices"
{txt}
{com}. global dr_output_log = "$dr_root\outputs\logs"
{txt}
{com}. global dr_temp = "$dr_root\data\intermediate"
{txt}
{com}. cd "$dr_temp"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\data\intermediate
{txt}
{com}. 
. ****************************** Figure B1 ***************************************
. clear
{txt}
{com}. set obs 12
{txt}{p}
Number of observations ({bf:_N}) was 0,
now 12.
{p_end}

{com}. *Create time indicator
. egen t = seq(), f(0) t(3) 
{txt}
{com}. label var t "Time"
{txt}
{com}. *Create indicator for control, early cohort, late cohort
. egen treatment = seq(), f(1) t(3) b(4)
{txt}
{com}. gen g = "control" 
{txt}
{com}. replace g = "early" if treatment==2
{txt}(4 real changes made)

{com}. replace g = "late" if treatment==3
{txt}(4 real changes made)

{com}. 
. *Create acre-feet time series for control
. gen acre_feet = 170
{txt}
{com}. label var acre_feet "Acre-feet applied"
{txt}
{com}. 
. *Create acre-feet time series for early adopter
. replace acre_feet = 160 if t==0 & g=="early" 
{txt}(1 real change made)

{com}. replace acre_feet = 160 if t==1 & g=="early" 
{txt}(1 real change made)

{com}. replace acre_feet = 158 if t==2 & g=="early"
{txt}(1 real change made)

{com}. replace acre_feet = 140 if t==3 & g=="early"
{txt}(1 real change made)

{com}. 
. *Create acre-feet time series for late adopters
. replace acre_feet = 165 if t==0 & g=="late"
{txt}(1 real change made)

{com}. replace acre_feet = 165 if t==1 & g=="late"
{txt}(1 real change made)

{com}. replace acre_feet = 165 if t==2 & g=="late"
{txt}(1 real change made)

{com}. replace acre_feet = 163 if t==3 & g=="late"
{txt}(1 real change made)

{com}. 
. *Drop if t==0
. drop if t==0
{txt}(3 observations deleted)

{com}. 
. *Create binary treatment indicator
. gen treated=0
{txt}
{com}. replace treated=1 if treatment!=1 & t >= treatment
{txt}(3 real changes made)

{com}. 
. *Plot the time series
.         tw (line acre_feet t if g=="control", lcolor(orange)) ///
>                 (line acre_feet t if g=="early" & t <= 1, lcolor(navy)) ///
>                 (line acre_feet t if g=="early" & t >= 1, lcolor(navy) lpattern(dash)) ///
>                 (line acre_feet t if g=="late" & t <= 2, lcolor(purple)) ///
>                 (line acre_feet t if g=="late" & t >= 2, lcolor(purple) lpattern(dash)) ///
>                 (scatter acre_feet t if g=="control", mcolor(orange) msymbol(O)) ///
>                 (scatter acre_feet t if  g=="late" & t < 3, mcolor(purple) msymbol(O)) ///
>                 (scatter acre_feet t if  g=="late" & t >= 3, mcolor(purple) msymbol(T)) ///
>                 (scatter acre_feet t if  g=="early" & t < 2, mcolor(navy)) ///
>                 (scatter acre_feet t if  g=="early" & t >= 2, mcolor(navy) msymbol(T)) ///
>                 (scatter acre_feet t if  g=="early" & t > 3, mcolor(black) msymbol(O)) ///
>                 (scatter acre_feet t if  g=="early" & t > 3, mcolor(black) msymbol(T)) ///
>                 (line acre_feet t if  g=="early" & t > 3, lcolor(black) lpattern(dash)), ///
>                 ysc(r(135 175)) ylabel(140(10)170) xlabel(1(1)3) graphregion(color(white)) ///
>                 title("") ///
>                 ytitle("Acre-feet applied") ///
>                 legend(cols(2) order(1 13 4 11 2 12) label(1 "Control group") ///
>                 position(6) ///
>                 labe(2 "Early adopter") label(4 "Late adopter") ///
>                 label(11 "Old technology") label(12 "New technology") label(13 "Post adoption")) 
{p 0 4 2}
{txt}(note:  named style
i not found in class
symbol,  default attributes used)
{p_end}
{res}{txt}
{com}.                 
. graph export "${c -(}dr_output_app{c )-}\figureB1.tif", replace wid(6500) height(6500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureB1.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
. ****************************** Figure B2 ***************************************
. *Plot each of the 2x2's 
. *Start with Early Group versus Untreated Group
. tw (connected acre_feet t if g=="control", lcolor(orange) mcolor(orange) msymbol(O)) ///
>         (connected acre_feet t if g=="early" & t <= 1, lcolor(navy) mcolor(navy)) ///
>         (line acre_feet t if g=="early" & t >= 1 & t<=2, lcolor(navy) lpattern(dash)) ///
>         (connected acre_feet t if g=="early" & t >= 2, lcolor(navy) mcolor(navy) msymbol(T) lpattern(dash)) ///
>         (line acre_feet t if g=="control" & t > 3, lcolor(orange)) ///
>         (line acre_feet t if g=="late" & t > 3, lcolor(purple)) ///
>         (line acre_feet t if g=="early" & t > 3, lcolor(navy)) ///
>         (scatter acre_feet t if  g=="early" & t > 3, mcolor(black) msymbol(O)) ///Add these in for the legend entries
>         (scatter acre_feet t if  g=="early" & t > 3, mcolor(black) msymbol(T)) ///
>         (line acre_feet t if  g=="early" & t > 3, lcolor(black) lpattern(dash)), ///
>         title("(a) Early versus control", size(medium)) ///
>         ytitle("") ///
>         xtitle("") ///
>         ysc(r(135 175)) ylabel(140(10)170) xlabel(1(1)3) graphregion(color(white)) ///
>         legend(cols(2) order(5 10 6 8 7 9) label(5 "Control group") ///
>                 label(7 "Early adopter") label(6 "Late adopter") ///
>                 label(8 "Old technology") label(9 "New technology") label(10 "Post adoption") ///
>                 position(6)) ///
>         name(early_vs_control, replace)
{res}{txt}
{com}.         
. *Late Group versus Untreated Group
. tw (connected acre_feet t if g=="control", lcolor(orange) mcolor(orange) msymbol(O)) ///
>         (connected acre_feet t if g=="late" & t <= 2, lcolor(purple) mcolor(purple)) ///
>         (line acre_feet t if g=="late" & t >= 2, lcolor(purple) mcolor(purple) lpattern(dash)) ///
>         (scatter acre_feet t if g=="late" & t > 2, mcolor(purple) msymbol(T)), ///
>         title("(b) Late versus control", size(medium)) ///
>         ytitle("") ///
>         xtitle("") ///
>         ysc(r(135 175)) ylabel(140(10)170) xlabel(1(1)3) graphregion(color(white)) ///
>         legend(off) ///
>         name(late_vs_control, replace)
{res}{txt}
{com}.         
. *Early group versus late group, before 2
. tw (connected acre_feet t if g=="early" & t <= 1, lcolor(navy) mcolor(navy) msymbol(O)) ///
>         (line acre_feet t if g=="early" & inrange(t, 1, 2), lcolor(navy) lpattern(dash)) ///
>         (scatter acre_feet t if g=="early" & t==2, mcolor(navy) msymbol(T)) ///
>         (connected acre_feet t if g=="late" & t <= 2, lcolor(purple) mcolor(purple) msymbol(O)), ///
>         title("(c) Early versus late, {c -(}it:t{c -(}&le{c )-}2{c )-}", size(medium)) ///
>         ytitle("") ///
>         xtitle("") ///
>         ysc(r(135 175)) ylabel(140(10)170) xlabel(1(1)3) graphregion(color(white)) ///
>         legend(off) ///
>         name(early_vs_late, replace)
{res}{txt}
{com}.         
. *Late group versus early group, after 2
. tw (connected acre_feet t if g=="early" & t >= 2, lcolor(navy) lpattern(dash) mcolor(navy) msymbol(T)) ///
>         (line acre_feet t if g=="late" & t >= 2, lcolor(purple) lpattern(dash)) ///
>         (scatter acre_feet t if g=="late" & t == 2, mcolor(purple)  msymbol(O)) ///
>         (scatter acre_feet t if g=="late" & t > 2, mcolor(purple) msymbol(T)), ///
>         title("(d) Late versus early, {c -(}it:t{c -(}&ge{c )-}2{c )-}", size(medium)) ///
>         ytitle("") ///
>         xtitle("") ///
>         ysc(r(135 175)) ylabel(140(10)170) xlabel(1(1)3) graphregion(color(white)) ///
>         legend(off) ///
>         name(late_vs_early, replace)
{res}{txt}
{com}. 
. *Combine the four graphs in a 2x2 matrix 
. grc1leg2 early_vs_control late_vs_control early_vs_late late_vs_early, ///
>         rows(2) cols(2) legendfrom(early_vs_control) xcommon b2title("Time") ycommon l1title("Acre-feet applied") ///
>         labsize(vsmall) graphregion(color(white)) xsize(6.5) ysize(6.5) iscale(.8)
{txt}-grc1leg2- working...
{p 0 4 2}
{txt}(note:  named style
i not found in class
symbol,  default attributes used)
{p_end}
{res}{txt}Warning: Because the legend borrowed for the combined graph is not "complete",
automatic resizing of legend markers is disabled and {cmd:grc1leg2} ignores the option -lmsize-.
See the discussion of "known issues" in {cmd:grc1leg2}'s help file {help grc1leg2##known:here}.

{com}. graph export "${c -(}dr_output_app{c )-}\figureB2.tif", replace wid(6500) height(6500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureB2.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
{txt}end of do-file

{com}. 
.         /* Run do file creating Figure B3 */
.         do "${c -(}dr_code{c )-}/appendices/figureB3.do"
{txt}
{com}. /* "Efficiency and water use: Dynamic effects of irrigation technology adoption"
> by Micah Cameron-Harp and Nathan Hendricks
> 
> Code written by Micah Cameron-Harp
> May 16th, 2024
> 
> This do file runs the Monte Carlo simulation depicted in Figure B1 and then
>         creates Figure B3 displaying the resulting biased TWFE estimate.
> */
. 
. *Define directories and set working directory
.         /* NOTE - To replicate our results, you need to change the directory address in the next line */
. global dr_root = "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{txt}
{com}. global dr_data = "$dr_root\data"
{txt}
{com}. global dr_output = "$dr_root\outputs"
{txt}
{com}. global dr_output_main = "$dr_root\outputs\main_text"
{txt}
{com}. global dr_output_app = "$dr_root\outputs\appendices"
{txt}
{com}. global dr_output_log = "$dr_root\outputs\logs"
{txt}
{com}. global dr_temp = "$dr_root\data\intermediate"
{txt}
{com}. cd "$dr_temp"
{res}C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\data\intermediate
{txt}
{com}. 
. set seed 12345
{txt}
{com}. 
. local est = "twfe"
{txt}
{com}.         postfile buffer `est' using mcs_`est', replace
{txt}
{com}.         qui forvalues i=1/1000 {c -(}
{txt}
{com}.         postclose buffer 
{txt}
{com}. 
. 
. *Open the dataset containing the TWFE coefficients 
. use mcs_twfe, clear 
{txt}
{com}.         *Summarize the coefficient variable
.         sum twfe

{txt}    Variable {c |}        Obs        Mean    Std. dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 8}twfe {c |}{res}      1,000    1.005773    .1374955   .5776827   1.427295
{txt}
{com}.         *Histogram 
.         hist twfe, name(twfe_hist, replace) ///
>                 xtitle("Estimated effect of adoption using TWFE") ///
>                 title("Monte Carlo simulation results")
{txt}(bin={res}29{txt}, start={res}.57768273{txt}, width={res}.02929697{txt})
{res}{txt}
{com}. graph export "${c -(}dr_output_app{c )-}\figureB3.tif", replace wid(6500) height(4500)
{txt}{p 0 4 2}
file {bf}
C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices\figureB3.tif{rm}
saved as
TIFF
format
{p_end}

{com}. 
{txt}end of do-file

{com}.         
.         /* Run r script performing bacon decomposition and 
>                 then output Table B.1 and Figure B.4 */
.         rscript using "${c -(}dr_code{c )-}/appendices/bacon_decomp.R", ///
>                 args("${c -(}dr_root{c )-}") rversion(3.6)
{res}Using default path: C:/Program Files/R/R-4.3.3/bin/Rscript.exe
Version information:
[1] "R installation is version 4.3.3"

Running R script: C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\code/appendices/bacon_decomp.R
Args: "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
Begin R output:
________________________________________________________________________________
{ul:stdout}:
                      type  weight   avg_est
1 Earlier vs Later Treated 0.17718  -5.09249
2 Later vs Earlier Treated 0.58777 -18.31796
3     Treated vs Untreated 0.23505  -3.39660
                      type  weight   avg_est
1 Earlier vs Later Treated 0.17718  -5.09249
2 Later vs Earlier Treated 0.58777 -18.31796
3     Treated vs Untreated 0.23505  -3.39660
                      type  weight avg_est
1 Earlier vs Later Treated 0.17718 6.02539
2 Later vs Earlier Treated 0.58777 3.16348
3     Treated vs Untreated 0.23505 8.88920
                      type  weight  avg_est
1 Earlier vs Later Treated 0.17718 -0.08969
2 Later vs Earlier Treated 0.58777 -0.13314
3     Treated vs Untreated 0.23505 -0.07309
          used (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 1012276 54.1    2918856 155.9  4445034 237.4
Vcells 8341497 63.7   46522948 355.0 58153685 443.7
                      type  weight  avg_est
1 Earlier vs Later Treated 0.31697  3.90128
2 Later vs Earlier Treated 0.62320  4.61380
3     Treated vs Untreated 0.05983 20.42860
                      type  weight  avg_est
1 Earlier vs Later Treated 0.31697 -1.44465
2 Later vs Earlier Treated 0.62320 -0.39905
3     Treated vs Untreated 0.05983 -0.57905
                      type  weight avg_est
1 Earlier vs Later Treated 0.31697 0.02596
2 Later vs Earlier Treated 0.62320 0.02976
3     Treated vs Untreated 0.05983 0.09408
           used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells  1014429  54.2    3003526  160.5   6804912  363.5
Vcells 26918018 205.4  134186990 1023.8 167733737 1279.8
function (plot = NULL, xlim = c(0, 1), ylim = c(0, 1), clip = "off") 
{c -(}
    p <- ggplot() + coord_cartesian(xlim = xlim, ylim = ylim, 
        expand = FALSE, clip = clip) + scale_x_continuous(name = NULL) + 
        scale_y_continuous(name = NULL) + theme_nothing()
    if (!is.null(plot)) {c -(}
        p <- p + draw_plot(plot)
    {c )-}
    p
{c )-}
<bytecode: 0x000001a51eef5108>
<environment: namespace:cowplot>


{ul:stderr}:
Warning messages:
1: The `legend.text.align` argument of `theme()` is deprecated as of ggplot2
3.5.0.
ℹ Please use theme(legend.text = element_text(hjust)) instead. 
2: In get_plot_component(plot, "guide-box") :
  Multiple components found; returning the first one. To return all, use `return_all = TRUE`.
________________________________________________________________________________
...end R output
{txt}
{com}. 
. *Appendix C materials
.         /* Table C.1 contains the estimated average treatment effects for both 
>                 technology changes produced by TWFE and the Callaway & Sant'Anna 
>                 estimator in levels. The "figure3.do" file, executed by the 
>                 "main_text_results.do" file, creates a dta file for each
>                 transition containing the ATT estimates in levels */
.                 *Load flood to cp/lepa ATT dta file
.                         use "${c -(}dr_output_app{c )-}/floodtocplepa_att_twfecs.dta", clear
{txt}
{com}.                 *Append the ATT estimates for cp to LEPA transition
.                         append using "${c -(}dr_output_app{c )-}/cptolepa_att_twfecs.dta"
{txt}
{com}.                 *Drop scaled estimate variables
.                         drop scaled*
{txt}
{com}.                 *Save 
.                         export delimited using "${c -(}dr_output_app{c )-}/tableC1.csv", replace                  
{res}{txt}file {bf:C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/tableC1.csv} saved

{com}.                 
.         /* Tables C.2 and C.3 contain the estimated cohort treatment effects for
>                 the change from flood to traditional center pivot or LEPA irrigation and from
>                 tranditional center pivot to LEPA, respectively. The estimates for  
>                 both tables are produced using the Callaway & Sant'Anna 
>                 estimator by the "cs_estimates.R" rscript run by the 
>                 "main_text_results.do" file. */
.                 /* Table C.2 -Load in the sheet containing the cohort treatment effects 
>                         from the flood to cp or lepa excel file containing average, cohort, 
>                         and dynamic effects. */                 
.                         import excel "${c -(}dr_temp{c )-}/cs_floodtocporlepa_91_15_nyt.xlsx", ///
>                                 sheet("cs_group") firstrow clear
{res}{text}(8 vars, 72 obs)

{com}.                         *Create variable showing which transition it is
.                         gen transition = "flood to cp/LEPA"
{txt}
{com}.                         *Save as tableC2.csv
.                         export delimited using "${c -(}dr_output_app{c )-}/tableC2.csv", replace
{res}{txt}file {bf:C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/tableC2.csv} saved

{com}.                 /* Table C.3 - Load in the sheet containing the cohort treatment effects
>                         from the flood to cp or lepa excel file containing average, cohort, 
>                         and dynamic effects. */                 
.                         import excel "${c -(}dr_temp{c )-}/cs_cptolepa.xlsx", ///
>                                 sheet("cs_group") firstrow clear
{res}{text}(8 vars, 84 obs)

{com}.                         *Create variable showing which transition it is
.                         gen transition = "cp to LEPA"
{txt}
{com}.                         *Save as tableC3.csv
.                         export delimited using "${c -(}dr_output_app{c )-}/tableC3.csv", replace
{res}{txt}file {bf:C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/tableC3.csv} saved

{com}. 
.         /* Table C.4 - Run r script estimating effects of transitioning from 
>                 flood irrigation to traditional center pivot and from flood irrigation
>                 to LEPA separately. */
.                 rscript using "${c -(}dr_code{c )-}/appendices/tableC4.R", ///
>                         args("${c -(}dr_root{c )-}") rversion(3.6)
{res}Using default path: C:/Program Files/R/R-4.3.3/bin/Rscript.exe
Version information:
[1] "R installation is version 4.3.3"

Running R script: C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\code/appendices/tableC4.R
Args: "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
Begin R output:
________________________________________________________________________________
{ul:stdout}:


{ul:stderr}:
Warning messages:
1: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Dropped 153 units that were already treated in the first period.
2: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Dropped 153 units that were already treated in the first period.
3: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Dropped 153 units that were already treated in the first period.
________________________________________________________________________________
...end R output
{txt}
{com}.                         
.         /* Table C.5 - Run r script estimating effects of both transitions on the 
>                 percent of water right groups' irrigated acreage planted to five
>                 crops using Callaway and Sant'Anna estimator. The crops are: alfalfa,
>                 corn, sorghum, soybeans, and wheat. */
.                 rscript using "${c -(}dr_code{c )-}/appendices/cs_estimates_frac_crop.R", ///
>                         args("${c -(}dr_root{c )-}") rversion(3.6)                
{res}Using default path: C:/Program Files/R/R-4.3.3/bin/Rscript.exe
Version information:
[1] "R installation is version 4.3.3"

Running R script: C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\code/appendices/cs_estimates_frac_crop.R
Args: "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
Begin R output:
________________________________________________________________________________
{ul:stdout}:
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 2253488 120.4    4713020 251.8  4713020 251.8
Vcells 6354378  48.5   38933058 297.1 48666322 371.3
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 2253930 120.4    7008345 374.3  7570844 404.4
Vcells 9296506  71.0   77982060 595.0 97477574 743.7


{ul:stderr}:
Warning messages:
1: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Be aware that there are some small groups in your dataset.
  Check groups: 2015.
2: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Be aware that there are some small groups in your dataset.
  Check groups: 2015.
3: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Be aware that there are some small groups in your dataset.
  Check groups: 2015.
4: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Be aware that there are some small groups in your dataset.
  Check groups: 2015.
5: In pre_process_did(yname = yname, tname = tname, idname = idname,  :
  Be aware that there are some small groups in your dataset.
  Check groups: 2015.
________________________________________________________________________________
...end R output
{txt}
{com}.                 
.         /* Tables C.6 and C.7 contain the estimated dynamic treatment effects for
>                 the change from flood to traditional center pivot or LEPA irrigation and from
>                 tranditional center pivot to LEPA, respectively. The estimates for  
>                 both tables are produced using the Callaway & Sant'Anna 
>                 estimator by the "cs_estimates.R" rscript run by the 
>                 "main_text_results.do" file. */
.                 /* Table C.6 - Load in the sheet containing the dynamic treatment effects 
>                         from the flood to cp or lepa excel file containing average, cohort, 
>                         and dynamic effects. */                 
.                         import excel "${c -(}dr_temp{c )-}/cs_floodtocporlepa_91_15_nyt.xlsx", ///
>                                 sheet("cs_event") firstrow clear
{res}{text}(8 vars, 141 obs)

{com}.                         *Create variable showing which transition it is
.                         gen transition = "flood to cp/LEPA"
{txt}
{com}.                         *Save as tableC6.csv
.                         export delimited using "${c -(}dr_output_app{c )-}/tableC6.csv", replace
{res}{txt}file {bf:C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/tableC6.csv} saved

{com}.                 /* Table C.7 - Load in the sheet containing the dynamic treatment effects
>                         from the flood to cp or lepa excel file containing average, cohort, 
>                         and dynamic effects. */                 
.                         import excel "${c -(}dr_temp{c )-}/cs_cptolepa.xlsx", ///
>                                 sheet("cs_event") firstrow clear
{res}{text}(8 vars, 165 obs)

{com}.                         *Create variable showing which transition it is
.                         gen transition = "cp to LEPA"
{txt}
{com}.                         *Save as tableC7.csv
.                         export delimited using "${c -(}dr_output_app{c )-}/tableC7.csv", replace
{res}{txt}file {bf:C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\outputs\appendices/tableC7.csv} saved

{com}. 
. *Appendix D materials
.         /* Table D.1 & D.2 - Run r script performing the parallel trends pre-test
>                 for both transitions and store the output for tables D.1 and D.2. */
.                 rscript using "${c -(}dr_code{c )-}/appendices/tableD1andD2.R", ///
>                         args("${c -(}dr_root{c )-}") rversion(3.6)
{res}Using default path: C:/Program Files/R/R-4.3.3/bin/Rscript.exe
Version information:
[1] "R installation is version 4.3.3"

Running R script: C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials\code/appendices/tableD1andD2.R
Args: "C:\Users\Micah\Dropbox\Irrigation technology transition\final revisions for conditional acceptance\replication materials"
{err}{hline 2}Break{hline 2}
{txt}{search r(1), local:r(1);}

end of do-file

{err}{hline 2}Break{hline 2}
{txt}{search r(1), local:r(1);}

{com}. exit, clear
